package com.app.ytong.bean;

import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;
import java.util.List;

import my.MathUtils;

public class SupplierListData extends BasisBean {

    /**
     *    {
     *       "cid": "1485906705345241089",
     *       "aid": "2",
     *       "kid": "1485870874584473601",
     *       "kna": "供应商"
     *       "cno": "10001",
     *       "cna": "供应商1",
     *       "cdr": "厦门",
     *       "ctel": "1",
     *       "cmn": "王",
     *       "crd": "123456",
     *       "path": null,
     *       "cdno": null,
     *       "uno": "admin"
     *        "tracelist": [
     *       {
     *         "aid": "2",
     *         "tid": "1485870237499027458",
     *         "tna": "牡丹",
     *         "cid": "1485904862334509058",
     *         "tra": -20
     *       },
     *       {
     *         "aid": "2",
     *         "tid": "1485870268331356161",
     *         "tna": "寿眉",
     *         "cid": "1485904862334509058",
     *         "tra": -10
     *       },
     *       {
     *         "aid": "2",
     *         "tid": "1485870294365401089",
     *         "tna": "银针",
     *         "cid": "1485904862334509058",
     *         "tra": -40
     *       }
     *     ]
     *     }
     */
    private static final long serialVersionUID = 1L;


    @JSONField(name = "cid")
    private String cid;
    @JSONField(name = "aid")
    private String aid;
    @JSONField(name = "kid")
    private String kid;
    @JSONField(name = "kna")
    private String kna;
    @JSONField(name = "cno")
    private String cno;
    @JSONField(name = "cna")
    private String cna;
    @JSONField(name = "cdr")
    private String cdr;
    @JSONField(name = "ctel")
    private String ctel;
    @JSONField(name = "cmn")
    private String cmn;
    @JSONField(name = "crd")
    private String crd;
    @JSONField(name = "path")
    private String path;
    @JSONField(name = "cdno")
    private String cdno;
    @JSONField(name = "uno")
    private String uno;
    @JSONField(name = "acr")
    private String acr;  //亩数

    @JSONField(name = "prp")
    private String prp;  //生态茶、台地茶等

    @JSONField(name = "istra")
    private String  istra;    //1可以欠    其他不可以

    @JSONField(name = "tracelist")
    private ArrayList<TraceListData> tracelist = new ArrayList<>();

    @JSONField(name = "bno")
    private String bno;         //大数据溯源码

    public SupplierListData() {
    }


    @JSONField(serialize = false)
    public boolean getAllTraIsEmpty(){
        for (TraceListData data : tracelist){
            if(!TextUtils.isEmpty(data.getEditTra())){
                return false;
            }
        }
        return true;
    }


    @JSONField(serialize = false)
    public  void setEditTraByTid(String tid,String value){
        for (TraceListData data : tracelist){
            if(tid.equals(data.getTid())){
                data.setEditTra(value);
            }
        }
    }

    @JSONField(serialize = false)
    public  String getTraByTid(String tid){
        String tra = "0";
        for (TraceListData data : tracelist){
            if(tid.equals(data.getTid())){
                tra = MathUtils.add(tra,data.getTra());
            }
        }
        return tra;
    }

    @JSONField(serialize = false)
    public  void setTraByTid(String tid,String tna,String cid,String tra){
        TraceListData data = getTraceByTid(tid);
        if(data != null){
            data.setTna(tna);
            data.setTra(MathUtils.compareTo(tra,"0")==-1?tra:"0");
        }else {
            data = new TraceListData();
            data.setAid(LoginBean.getInstance().getAid());
            data.setTid(tid);
            data.setTna(tna);
            data.setCid(cid);
            data.setTra(MathUtils.compareTo(tra,"0")==-1?tra:"0");
            tracelist.add(data);
        }


    }

    @JSONField(serialize = false)
    public  TraceListData getTraceByTid (String tid){
        for (TraceListData data : tracelist){
            if(tid.equals(data.getTid())){
                return data;
            }
        }

        return null;
    }


    public void setAutoBno(String value){
//        http://www.fdbcdsj.cn:8880/QRHome/Scan/79855
        String a = value.replace("http://www.fdbcdsj.cn:8880/QRHome/Scan/","");
        this.bno = a;
    }

    public String getAutoBno(){
        if(TextUtils.isEmpty(getBno()) || "null".equals(getBno())) return null;
        return "http://www.fdbcdsj.cn:8880/QRHome/Scan/"+getBno();
    }

    public String getAcr() {
        return acr;
    }

    public void setAcr(String acr) {
        this.acr = acr;
    }

    public String getPrp() {
        return prp;
    }

    public void setPrp(String prp) {
        this.prp = prp;
    }

    public String getBno() {
        return bno;
    }

    public void setBno(String bno) {
        this.bno = bno;
    }

    public ArrayList<TraceListData> getTracelist() {
        return tracelist;
    }

    public void setTracelist(ArrayList<TraceListData> tracelist) {
        this.tracelist = tracelist;
    }



    public String getKna() {
        return kna;
    }

    public void setKna(String kna) {
        this.kna = kna;
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

    public String getAid() {
        return aid;
    }

    public void setAid(String aid) {
        this.aid = aid;
    }

    public String getKid() {
        return kid;
    }

    public void setKid(String kid) {
        this.kid = kid;
    }

    public String getCno() {
        return cno;
    }

    public void setCno(String cno) {
        this.cno = cno;
    }

    public String getCna() {
        return cna;
    }

    public void setCna(String cna) {
        this.cna = cna;
    }

    public String getCdr() {
        return cdr;
    }

    public void setCdr(String cdr) {
        this.cdr = cdr;
    }

    public String getIstra() {
        if(TextUtils.isEmpty(istra) || "null".equals(istra))return "1";
        return istra;
    }

    public void setIstra(String istra) {
        this.istra = istra;
    }

    public String getCtel() {
        return ctel;
    }

    public void setCtel(String ctel) {
        this.ctel = ctel;
    }

    public String getCmn() {
        return cmn;
    }

    public void setCmn(String cmn) {
        this.cmn = cmn;
    }

    public String getCrd() {
        return crd;
    }

    public void setCrd(String crd) {
        this.crd = crd;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getCdno() {
        return cdno;
    }

    public void setCdno(String cdno) {
        this.cdno = cdno;
    }

    public String getUno() {
        return uno;
    }

    public void setUno(String uno) {
        this.uno = uno;
    }

}
